/*
* ===================================================
*
*       Filename:  map.cc
*
*
*        Created:  12/10/2011 09:39:31 AM
*       Revision:  none
*       Compiler:  gcc
*
*         Author:  durand_y, <durand.yoan@gmail.com>
*
* ===================================================
*/

#include "map.hh"
#include "cell.hh"
#include <sstream>

Map*
Map::instance_ = 0;

Map&
Map::GetInstance ()
{
	if (instance_ == 0)
		instance_ = new Map ();
	return (*instance_);
}
Map::Map (int x, int y)
	: width_ (x),
	  height_ (y)
{
	std::vector<std::vector <Cell*> > map;
	for (int j = 0; j < x; j++)
	{
	  std::vector<Cell *> line;
		for (int i = 0; i < y; i++)
		{
			Cell* c = new Cell;
			line.push_back (c);
		}

		map.push_back (line);
	}
	map_ = map;
	team_ = new Team;
}

Map::Map ()

{
}

Map :: ~Map ()
{
}

void
Map::print ()
{
	std::cout << "  |";
	for (int i = 1; i < width_ ; i++)
	{
		if (i < 10)
			std::cout << 0;
		std::cout << i;
		std::cout  << " ";
	}

	std::cout << width_ <<"|"<< std::endl;
	for (int i = 0; i < width_ + 1; i++)
		std::cout << "---";
	std::cout << std::endl;
	for (int i = 0; i < height_ ; ++i)
	{
		if ((i + 1) < 10)
			std::cout << 0;
		std::cout << i + 1;
		std::cout << "|";
		for (int j = 0; j < width_ ; j++)
		{
			if (map_[i][j]->get_piece () != 0)
			{
				map_[i][j]->get_piece ()->print ();
				std::cout << "|";
			}
			else
				std::cout << "  |";
		}
		std::cout << std::endl;
		std::cout << "  -";
		for (int j = 1; j < width_ + 1; j++)
			std::cout << "---";
		std::cout << std::endl;
	}
}

